/*
 * Description:  update Utils in windows
 */

#ifndef WINUPDATEUTILS_H
#define WINUPDATEUTILS_H
#include <windows.h>
#include <string>
#include <vector>

namespace COMMON {

const std::string BASE_PATH = "SOFTWARE\\Microsoft\\WindowsUpdate\\UX\\Settings";
const std::string BAK_PATH = "SOFTWARE\\kiddo\\bak\\UX\\Settings";

const std::string PFEATURE_ENDTIME = "PauseFeatureUpdatesEndTime";
const std::string PFEATURE_STARTTIME = "PauseFeatureUpdatesStartTime";
const std::string PQUALITY_ENDTIME = "PauseQualityUpdatesEndTime";
const std::string PQUALITY_STARTTIME = "PauseQualityUpdatesStartTime";
const std::string PEXPIRY_TIME = "PauseUpdatesExpiryTime";
const std::string PSTART_TIME = "PauseUpdatesStartTime";
const std::vector<std::string> UPDATES_SETTING_KEYS = {
    PFEATURE_ENDTIME, PFEATURE_STARTTIME, PQUALITY_ENDTIME, PQUALITY_STARTTIME, PEXPIRY_TIME, PSTART_TIME
    };

const std::string KIDDO_UPGRADE_PATH = "SOFTWARE\\WOW6432Node\\Microsoft\\Windows\\CurrentVersion\\VMConfig";
struct RegInfo {
    std::string regKey;
    std::string regWord;
    std::string regValue;
    std::string bakKey;
    std::string cmdStr;
    DWORD regValueD;
};

const std::vector<RegInfo> UPGRADE_HKCU_ITEMS = {
    {"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
        "ListviewAlphaSelect", "", "\\Explorer\\Advanced", "", 1},
    {"Control Panel\\Desktop\\WindowMetrics",
        "MinAnimate", "1", "\\Desktop\\WindowMetrics"},
    {"Software\\Microsoft\\TabletTip\\1.7",
        "TouchKeyboardTapInvoke", "", "\\TabletTip\\1.7", "", 2},
    {"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Advanced",
        "TaskbarDa", "", "\\Explorer\\Advanced", "", 0},
    };

const std::vector<RegInfo> UPGRADE_HKLM_ITEMS = {
    {"SYSTEM\\CurrentControlSet\\Services\\HTTP\\Parameters",
        "EnableHttpKeepAlive", "", "\\HTTP\\Parameters", "", 1},
    {"SYSTEM\\CurrentControlSet\\Services\\HTTP\\Parameters",
        "MaxConnections", "", "\\HTTP\\Parameters", "", 296},
    {"SYSTEM\\CurrentControlSet\\Services\\HTTP\\Parameters",
        "EnableTcpTimedWaitDelay", "", "\\HTTP\\Parameters", "", 1},
    {"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters", "TcpAckFrequency",
        "", "\\Tcpip\\Parameters", "", 1},
    {"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters",
        "MaxUserPort", "", "\\Tcpip\\Parameters", "", 65534},
    {"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Explorer\\scaling",
        "Monitorsize", "11", "\\Explorer\\scaling"},
    {"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",
        "ConsentPromptBehaviorAdmin", "", "\\Policies\\System", "", 5},
    {"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",
        "EnableLUA", "", "\\Policies\\System", "", 1},
    {"SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Policies\\System",
        "PromptOnSecureDesktop", "", "\\Policies\\System", "", 0},
    };

const std::string EDGE_USERDATA_CMD_PRE =
    "echo {\"browser\":{\"enabled_labs_experiments\":[\"smooth-scrolling@1\",\"windows-scrolling-personality@1\",";
const std::string EDGE_USERDATA_CMD_AFTER =
    "\"enable-parallel-downloading@1\"]}}> \"%localappdata%\\Microsoft\\Edge\\User Data\\Local State\"";
const std::string CHROME_USERDATA_CMD_PRE =
    "echo {\"browser\":{\"enabled_labs_experiments\":[\"smooth-scrolling@1\",\"windows-scrolling-personality@1\",";
const std::string CHROME_USERDATA_CMD_AFTER =
    "\"enable-parallel-downloading@1\"]}}> \"%localappdata%\\Google\\Chrome\\User Data\\Local State\"";
const std::vector<RegInfo> UPGRADE_CMD_ITEMS = {
    {"", "LocalState", "1", "\\Edge\\UserData", EDGE_USERDATA_CMD_PRE + EDGE_USERDATA_CMD_AFTER},
    {"", "LocalState", "1", "\\Chrome\\UserData", CHROME_USERDATA_CMD_PRE + CHROME_USERDATA_CMD_AFTER},
    {"", "TranscodedWallpaper", "1", "\\Windows\\Themes",
        "del \"C:\\Users\\WindowsVM\\AppData\\Roaming\\Microsoft\\Windows\\Themes\\TranscodedWallpaper\""},
    {"", "display", "1", "\\display",
        "echo y|cacls %PROGRAMDATA%\\display /c /t /p \"SYSTEM\":F \"Administrators\":F Users:R"},
    {"", "WinEvtMonitor", "1", "\\WinEvtMonitor",
        "echo y|cacls %PROGRAMDATA%\\WinEvtMonitor /c /t /p \"SYSTEM\":F \"Administrators\":F Users:R"},
    {"", "AppFilter", "1", "\\AppFilter ",
        "echo y|cacls %PROGRAMDATA%\\AppFilter  /c /t /p \"SYSTEM\":F \"Administrators\":F Users:R"},
    {"", "TranscodedWallpaper2", "1", "\\Windows\\Themes",
        "copy \"C:\\Windows\\Web\\Wallpaper\\Windows\\img19.jpg\" \"%appdata%\\Microsoft\\Windows\\Themes\""},
    {"", "TranscodedWallpaper1", "1", "\\Windows\\Themes",
        "del \"%appdata%\\Microsoft\\Windows\\Themes\\TranscodedWallpaper\""},
    {"", "TranscodedWallpaper3", "1","\\Windows\\Themes",
        "ren \"%appdata%\\Microsoft\\Windows\\Themes\\img19.jpg\" \"TranscodedWallpaper\""},
    };

class WinUpdateUtils {
public:
    /********************
    函数：CheckWinUpdating
    功能：检查当前是否正在更新
    参数：NA
    返回值：结果
    ********************/
    static bool CheckWinUpdating();

    /********************
    函数：DelayUpdate
    功能：推迟更新
    参数：NA
    返回值：NA
    ********************/
    static void DelayUpdate();

    /********************
    函数：restoreSetting
    功能：还原更新配置
    参数：NA
    返回值：NA
    ********************/
    static void RestoreSetting();

    /********************
    函数：UpgradeAgent
    功能：agent更新触发，安装脚本增量更新
    参数：NA
    返回值：NA
    ********************/
    static void UpgradeAgent();

private:
    static void UpgradeHKLM();
    static void UpgradeHKCU();
    static void UpgradeCMD();
};
}
#endif